package com.seu.me.test;

/**
 * @author liangfeihu
 * @since 2019/12/18 16:09
 */
public class DemoSort {
    public static void main(String[] args) {
        int[] arr = {4, 2, 3, 1};
        printArr(arr);
        System.out.println();
        selectSort(arr);
        //printArr(arr);
    }

    public static void selectSort(int[] arr) {

        for (int i = 0; i < arr.length - 1; i++) {
            int num = i;
            int j = i + 1;
            for (; j < arr.length; j++) {
                if (arr[j] < arr[num]) {
                    num = j;
                }
            }
            swap(arr, i, num);
        }
        printArr(arr);

    }

    public static void swap(int[] arr, int i, int num) {
        int temp;
        temp = arr[i];
        arr[i] = arr[num];
        arr[num] = temp;
    }

    public static void printArr(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]);
        }
    }
}
